﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class OuterProcedureHeadElement : InnerProcedureHeadElement
    {
        protected IdElement classname;

        public IdElement ClassName { get { return classname; } set { classname = value; } }

        public OuterProcedureHeadElement(TokenInfo Type, IdElement ClassName, TokenInfo Name, List<FunctionVarDeclarationElement> Vars, List<DirectiveElement> Directives, List<TokenInfo> Comments)
            : base(Type, Name, Vars, Directives, Comments)
        {
            classname = ClassName;
        }

        public override string ToString()
        {
            string result = string.Format("{0} {1}{2}", type, (classname != null) ? string.Format("{0}.", classname) : string.Empty, id);
            if ((vars != null) && (vars.Count > 0))
                result += string.Format("({0})", vars.Join("; "));
            if ((directives != null) && (directives.Count > 0))
                result += string.Format("; {0}", directives.Join("; "));
            return string.Format("{0};", result);
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            if (classname != null)
                yield return classname;
            IEnumerator<ISyntaxTreeElement> baseEnumerator = base.CreateEnumerator();
            while (baseEnumerator.MoveNext())
                yield return baseEnumerator.Current;
        }
    }
}
